//
//  ReleaseImageItemCell.m
//  NoNeedle
//
//  Created by shui on 2017/3/7.
//  Copyright © 2017年 shui. All rights reserved.
//

#import "ReleaseImageItemCell.h"

#define screenS [[UIScreen mainScreen] scale]

@implementation ReleaseImageItemCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self) {
        [self createUI];
    }
    return self;
}

- (void)createUI {
    self.imageView = [[UIImageView alloc]initWithFrame:self.bounds];
    self.imageView.contentMode = UIViewContentModeScaleAspectFill;
    self.imageView.clipsToBounds = YES;
    self.imageView.contentScaleFactor = screenS;
    self.imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    self.imageView.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:self.imageView];
    self.cancelButton = [[UIButton alloc]initWithFrame:CGRectZero];
    [self.cancelButton addTarget:self action:@selector(cancelButtonAction) forControlEvents:UIControlEventTouchUpInside];

    [self.cancelButton setImage:[UIImage imageNamed:@"icon_release_close"] forState:UIControlStateNormal];
    [self addSubview:self.cancelButton];
    [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(0);
        make.right.equalTo(self).offset(-3);
        make.width.height.mas_equalTo(self.frame.size.height / 4);
    }];
}

// 删除按钮响应
- (void)cancelButtonAction {
    if([self.preVC isKindOfClass:[PublishImageViewController class]]) {
        PublishImageViewController *releaseVC = (PublishImageViewController *)self.preVC;
        [releaseVC.imageArray removeObjectAtIndex:self.indexPath.item];
        [releaseVC.imageCollectionView reloadData];
        
         [[NSNotificationCenter  defaultCenter] postNotificationName:@"deledate" object:@"deledate"];
    }
    
//    if([self.preVC isKindOfClass:[AddThirdCheckViewController class]]) {
//        AddThirdCheckViewController *releaseVC = (AddThirdCheckViewController *)self.preVC;
//        [releaseVC.imageArray removeObjectAtIndex:self.indexPath.item];
//        [releaseVC.imageCollectionView reloadData];
//    }
//    if([self.preVC isKindOfClass:[AddDiagnoseViewController class]]) {
//        AddDiagnoseViewController *releaseVC = (AddDiagnoseViewController *)self.preVC;
//        [releaseVC.imageArray removeObjectAtIndex:self.indexPath.item];
//        [releaseVC.imageCollectionView reloadData];
//    }
    
}

@end
